package com.yuxi.al.single;

/**
 * 懒汉式单例
 * Created by yuxi on 2017/8/27.
 */
public class LazySingle {
    public static void main(String[] args) {
        LazySingles lazySingles1 = LazySingles.getInstance();
        LazySingles lazySingles2 = LazySingles.getInstance();
        System.out.println(lazySingles1.equals(lazySingles2));
    }
}

//加锁了性能方面会有损失
class LazySingles {
    private static LazySingles single;

    private LazySingles() {
    }

    public static synchronized LazySingles getInstance() {
        if (single == null) {
            single = new LazySingles();
        }
        return single;
    }
}